package cn.digitalize.system.modular.auth.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.digitalize.common.pojo.result.ResultData;
import cn.digitalize.system.modular.auth.param.AuthLoginParam;
import cn.digitalize.system.modular.auth.result.BaseLoginUser;
import cn.digitalize.system.modular.auth.service.AuthService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by ZhangCheng on 2023/06/02 (登录授权)
 */
@RestController
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/auth/doLogin")
    public ResultData<String> doLogin(AuthLoginParam authLoginParam) {
        System.out.println("xxxxxxxxxxxxxxxx");
        return ResultData.query(authService.doLogin(authLoginParam));
    }

    @GetMapping("/auth/getLoginUser")
    public ResultData<BaseLoginUser> getLoginUser() {
        BaseLoginUser baseLoginUser = new BaseLoginUser();
        baseLoginUser.setAccount("test");
        return ResultData.query(baseLoginUser);
        //return ResultData.query(authService.getLoginUser());
    }

    /**
     * 系统退出
     *
     * @return
     */
    @GetMapping("/auth/doLogout")
    public ResultData<String> doLogout() {
        StpUtil.logout();
        return ResultData.success();
    }
}
